package cn.edu.ujn.multiple.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import cn.edu.ujn.multiple.model.BaseDict;
import cn.edu.ujn.multiple.model.Customer;
import cn.edu.ujn.multiple.model.Orders;
import cn.edu.ujn.multiple.service.ICustomerService;
import cn.edu.ujn.multiple.service.IOrdersService;
import cn.edu.ujn.multiple.util.Page;

@Controller
public class OrdersController {

	@Autowired
	private IOrdersService ordersService;
	@Autowired
	private ICustomerService customerService;
	@GetMapping("/orders")
	public String toOrder(Model model) {
		Customer associationCustomer = customerService.findByPrimaryKey(1);
		model.addAttribute("associationCustomer", associationCustomer);
		return "orders";
	}
	

	
	@GetMapping("/orders/list.action")
	public String query(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "5") Integer rows,
			String custId, String OrderId, String OrdersId,  Model m) {

		List<Orders> list = ordersService.selectByCustId(rows);
		Page<Orders> lists = ordersService.findOrdersList(page, rows, custId, OrderId, OrdersId);
		m.addAttribute("page", lists);

		return "orders";
	}
	
}
